package cn.tannn.ops.pwd.controller.dto;

import cn.tannn.jdevelops.annotations.jpa.JpaSelectIgnoreField;
import cn.tannn.jdevelops.annotations.jpa.JpaSelectOperator;
import cn.tannn.jdevelops.annotations.jpa.enums.SQLConnect;
import cn.tannn.jdevelops.annotations.jpa.enums.SQLOperatorWrapper;
import cn.tannn.jdevelops.jpa.request.PagingSorteds;
import cn.tannn.jdevelops.result.bean.SerializableBean;
import cn.tannn.ops.pwd.enums.KeePassStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;


/**
 * 分页查询密码
 *
 * @author tnnn
 * @version V1.0
 * @date 2023-02-20 09:28
 */
@Schema(description = "分页查询密码")
@Getter
@Setter
@ToString
public class KeePassPage extends SerializableBean<KeePassPage> {

    /**
     * 分组
     */
    @Schema(description = "分组")
    @JpaSelectOperator(operatorWrapper = SQLOperatorWrapper.LIKE, connect= SQLConnect.OR)
    String groupings;

    /**
     * 密码标题
     */
    @Schema(description = "密码标题")
    @JpaSelectOperator(operatorWrapper = SQLOperatorWrapper.LIKE, connect= SQLConnect.OR)
    String title;

    /**
     * 用户名
     */
    @Schema(description = "用户名")
    @JpaSelectOperator(operatorWrapper = SQLOperatorWrapper.LIKE)
    String username;





    /**
     * 状态 VALID("有效"), RECYCLED("回收站");
     * @see KeePassStatus
     */
    @Schema(description = "状态 VALID(\"有效\"), RECYCLED(\"回收站\");")
    @JpaSelectOperator(operatorWrapper = SQLOperatorWrapper.EQ)
    KeePassStatus status;


    /**
     * 分页排序
     */
    @Schema(description = "分页排序")
    @Valid
    @JpaSelectIgnoreField
    private PagingSorteds page;


    public PagingSorteds getPage() {
        if(page == null){
            return new PagingSorteds().fixSort(1,"id");
        }
        return page;
    }
}
